package com.boyi.cycling_master.https.utils;

import com.boyi.cycling_master.bean.LoginResponseBean;
import com.boyi.cycling_master.bean.ResponseBean;
import com.boyi.cycling_master.common.PostParams;
import com.boyi.cycling_master.https.apis.APIS;

import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * @author Lee_Mofeel
 * @version 1.0
 * @date ${Date} ${Time}
 * @Description
 */

public class UserRetrofit {
    private static final UserRetrofit ourInstance = new UserRetrofit();
    private static Retrofit retrofit ;
    public static UserRetrofit getInstance() {
        retrofit = new Retrofit.Builder().baseUrl(APIS.BASE_LOGIN_CONTROLLER_URL).addConverterFactory(GsonConverterFactory.create()).build();
        return ourInstance;
    }

    private UserRetrofit() {
    }
    /* POST 获取验证码 */
    public interface SmsCodePost{
        @POST("judgeUserName")
        Call<ResponseBean> getSms(@Body RequestBody body);
    }

    public void getSmsCodeByPost(Callback<ResponseBean> callback, Map<String,String> map){
        SmsCodePost smsCodePost = retrofit.create(SmsCodePost.class);
        Call<ResponseBean> call = smsCodePost.getSms(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }
    /* 校验密码 */
    public interface CheckedSmsCode{
        @POST("verifySmsCode")
        Call<ResponseBean> checkedSmsCode(@Body RequestBody body);
    }

    public void toCheckedSmsCode(Callback<ResponseBean> callback, Map<String,String> map){
        CheckedSmsCode checkedSmsCode = retrofit.create(CheckedSmsCode.class);
        Call<ResponseBean> call = checkedSmsCode.checkedSmsCode(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }
    /* 登陆请求 */
    public interface Login{
        @POST("loginUserModel")
        Call<LoginResponseBean> doLogin(@Body RequestBody body);
    }

    public void toLogin(Callback<LoginResponseBean> callback,Map<String,String> map){
        Login login = retrofit.create(Login.class);
        Call<LoginResponseBean> call = login.doLogin(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }
    /* 注册请求 */
    public interface Register{
        @POST("saveUserModel")
        Call<LoginResponseBean> doRegister(@Body RequestBody body);
    }

    public void toRegister(Callback<LoginResponseBean> callback,Map<String,String> map){
        Register register = retrofit.create(Register.class);
        Call<LoginResponseBean> call = register.doRegister(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }


    /* 第三方登录回传 */
    public interface OtherLogin{
        @POST("otherLogin")
        Call<LoginResponseBean> doOtherLogin(@Body RequestBody body);
    }

    public void toOhtherLogin(Callback<LoginResponseBean> callback,Map<String,String> map){
        OtherLogin otherLogin = retrofit.create(OtherLogin.class);
        Call<LoginResponseBean> call = otherLogin.doOtherLogin(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }

    /* 找回密码 */
    public interface RetrievePwd{
        @POST("resetPassword")
        Call<ResponseBean> doRetrievePwd(@Body RequestBody body);
    }

    public void toRetrievePwd(Callback<ResponseBean> callback,Map<String,String> map){
        RetrievePwd retrievePwd = retrofit.create(RetrievePwd.class);
        Call<ResponseBean> call = retrievePwd.doRetrievePwd(PostParams.makeRequestBody(map));
        call.enqueue(callback);
    }



}
